/*
 * @(#)MtmCalendarRecordMeeting.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.calendar.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.dcivision.calendar.bean.MtmCalendarRecordMeeting;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;

/**
  MtmCalendarRecordMeetingDAObject.java
  This class is the data access bean for table "MTM_CALENDAR_RECORD_MEETING".
  @author      Jenny Li
  @company     DCIVision Limited
  @creation date   05/12/2003
  @version     $Revision: 1.7 $
 */

public class MtmCalendarRecordMeetingDAObject
    extends AbstractDAObject {
  public static final String TABLE_NAME = "MTM_CALENDAR_RECORD_MEETING";

  public MtmCalendarRecordMeetingDAObject() {
    super();
  }

  public MtmCalendarRecordMeetingDAObject(Connection dbConn) {
    super(dbConn);
  }

  public MtmCalendarRecordMeetingDAObject(SessionContainer sessionContainer,
                                          Connection dbConn) {
    super(sessionContainer, dbConn);
  }

  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("CALENDAR_RECORD_ID");
    this.vecDBColumn.add("INVITED_ID");
    this.vecDBColumn.add("INVITED_ID_TYPE");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }

  protected synchronized AbstractBaseObject getByID(Integer id) throws
      ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.CALENDAR_RECORD_ID, A.INVITED_ID, A.INVITED_ID_TYPE, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_CALENDAR_RECORD_MEETING A");
        sqlStat.append("WHERE  A.ID = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        this.setPrepareStatement(preStat, 1, id);
        rs = preStat.executeQuery();
        if (rs.next()) {
          MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = new
              MtmCalendarRecordMeeting();
          tmpMtmCalendarRecordMeeting.setID(getResultSetInteger(rs, "ID"));
          tmpMtmCalendarRecordMeeting.setCalendarRecordID(getResultSetInteger(
              rs, "CALENDAR_RECORD_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedID(getResultSetInteger(rs,
              "INVITED_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedIDType(getResultSetString(rs,
              "INVITED_ID_TYPE"));
          tmpMtmCalendarRecordMeeting.setCreatorID(getResultSetInteger(rs,
              "CREATOR_ID"));
          tmpMtmCalendarRecordMeeting.setCreateDate(getResultSetTimestamp(rs,
              "CREATE_DATE"));
          tmpMtmCalendarRecordMeeting.setUpdaterID(getResultSetInteger(rs,
              "UPDATER_ID"));
          tmpMtmCalendarRecordMeeting.setUpdateDate(getResultSetTimestamp(rs,
              "UPDATE_DATE"));
          tmpMtmCalendarRecordMeeting.setCreatorName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getCreatorID()));
          tmpMtmCalendarRecordMeeting.setUpdaterName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getUpdaterID()));
          return (tmpMtmCalendarRecordMeeting);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
      } finally {
        try {
          rs.close();
        } catch (Exception ignore) {} finally {
          rs = null;
        }
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }

  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.CALENDAR_RECORD_ID, A.INVITED_ID, A.INVITED_ID_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_CALENDAR_RECORD_MEETING A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        this.setPrepareStatement(preStat, 1,
                                 GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = new
              MtmCalendarRecordMeeting();
          tmpMtmCalendarRecordMeeting.setID(getResultSetInteger(rs, "ID"));
          tmpMtmCalendarRecordMeeting.setCalendarRecordID(getResultSetInteger(
              rs, "CALENDAR_RECORD_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedID(getResultSetInteger(rs,
              "INVITED_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedIDType(getResultSetString(rs,
              "INVITED_ID_TYPE"));
          tmpMtmCalendarRecordMeeting.setRecordStatus(getResultSetString(rs,
              "RECORD_STATUS"));
          tmpMtmCalendarRecordMeeting.setUpdateCount(getResultSetInteger(rs,
              "UPDATE_COUNT"));
          tmpMtmCalendarRecordMeeting.setCreatorID(getResultSetInteger(rs,
              "CREATOR_ID"));
          tmpMtmCalendarRecordMeeting.setCreateDate(getResultSetTimestamp(rs,
              "CREATE_DATE"));
          tmpMtmCalendarRecordMeeting.setUpdaterID(getResultSetInteger(rs,
              "UPDATER_ID"));
          tmpMtmCalendarRecordMeeting.setUpdateDate(getResultSetTimestamp(rs,
              "UPDATE_DATE"));
          tmpMtmCalendarRecordMeeting.setCreatorName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getCreatorID()));
          tmpMtmCalendarRecordMeeting.setUpdaterName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getUpdaterID()));
          result.add(tmpMtmCalendarRecordMeeting);
        }
        return (result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle,
                                       sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try {
          rs.close();
        } catch (Exception ignore) {} finally {
          rs = null;
        }
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }

  protected synchronized List getList(AbstractSearchForm searchForm) throws
      ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());

    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.CALENDAR_RECORD_ID, A.INVITED_ID, A.INVITED_ID_TYPE, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   MTM_CALENDAR_RECORD_MEETING A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");

        // Form the WHERE clause for filtering.
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " +
                         searchForm.getBasicSearchType() + " ? ");
        }

        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " +
                         searchForm.getSortOrder());
        }

        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString());
        this.setPrepareStatement(preStatCnt, 1,
                                 GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.
              getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try {
          rsCnt.close();
        } catch (Exception ignore) {} finally {
          rsCnt = null;
        }
        try {
          preStatCnt.close();
        } catch (Exception ignore) {} finally {
          preStatCnt = null;
        }

        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1,
                                 GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.
              getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();

        this.positionCursor(rs, startOffset, pageSize);

        while (rs.next() && rowLoopCnt < pageSize) {
          MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = new
              MtmCalendarRecordMeeting();
          tmpMtmCalendarRecordMeeting.setID(getResultSetInteger(rs, "ID"));
          tmpMtmCalendarRecordMeeting.setCalendarRecordID(getResultSetInteger(
              rs, "CALENDAR_RECORD_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedID(getResultSetInteger(rs,
              "INVITED_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedIDType(getResultSetString(rs,
              "INVITED_ID_TYPE"));
          tmpMtmCalendarRecordMeeting.setRecordStatus(getResultSetString(rs,
              "RECORD_STATUS"));
          tmpMtmCalendarRecordMeeting.setUpdateCount(getResultSetInteger(rs,
              "UPDATE_COUNT"));
          tmpMtmCalendarRecordMeeting.setCreatorID(getResultSetInteger(rs,
              "CREATOR_ID"));
          tmpMtmCalendarRecordMeeting.setCreateDate(getResultSetTimestamp(rs,
              "CREATE_DATE"));
          tmpMtmCalendarRecordMeeting.setUpdaterID(getResultSetInteger(rs,
              "UPDATER_ID"));
          tmpMtmCalendarRecordMeeting.setUpdateDate(getResultSetTimestamp(rs,
              "UPDATE_DATE"));
          tmpMtmCalendarRecordMeeting.setCreatorName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getCreatorID()));
          tmpMtmCalendarRecordMeeting.setUpdaterName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getUpdaterID()));
          tmpMtmCalendarRecordMeeting.setRecordCount(totalNumOfRecord);
          tmpMtmCalendarRecordMeeting.setRowNum(startOffset++);
          ++rowLoopCnt;

          result.add(tmpMtmCalendarRecordMeeting);

        }
        return (result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle,
                                       sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try {
          rs.close();
        } catch (Exception ignore) {} finally {
          rs = null;
        }
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
        try {
          rsCnt.close();
        } catch (Exception ignore) {} finally {
          rsCnt = null;
        }
        try {
          preStatCnt.close();
        } catch (Exception ignore) {} finally {
          preStatCnt = null;
        }
      }
    }
  }

  protected void validateInsert(AbstractBaseObject obj) throws
      ApplicationException {
  }

  protected void validateUpdate(AbstractBaseObject obj) throws
      ApplicationException {
  }

  protected void validateDelete(AbstractBaseObject obj) throws
      ApplicationException {
  }

  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws
      ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = (
        MtmCalendarRecordMeeting) ( (MtmCalendarRecordMeeting) obj).clone();

    synchronized (dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        sqlStat.append("INTO   MTM_CALENDAR_RECORD_MEETING(ID, CALENDAR_RECORD_ID, INVITED_ID, INVITED_ID_TYPE, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        setPrepareStatement(preStat, 1, nextID);
        setPrepareStatement(preStat, 2,
                            tmpMtmCalendarRecordMeeting.getCalendarRecordID());
        setPrepareStatement(preStat, 3,
                            tmpMtmCalendarRecordMeeting.getInvitedID());
        setPrepareStatement(preStat, 4,
                            tmpMtmCalendarRecordMeeting.getInvitedIDType());
        setPrepareStatement(preStat, 5, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 6, currTime);
        setPrepareStatement(preStat, 7, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 8, currTime);
        preStat.executeUpdate();
        tmpMtmCalendarRecordMeeting.setID(nextID);
        tmpMtmCalendarRecordMeeting.setCreatorID(sessionContainer.
                                                 getUserRecordID());
        tmpMtmCalendarRecordMeeting.setCreateDate(currTime);
        tmpMtmCalendarRecordMeeting.setUpdaterID(sessionContainer.
                                                 getUserRecordID());
        tmpMtmCalendarRecordMeeting.setUpdateDate(currTime);
        tmpMtmCalendarRecordMeeting.setCreatorName(UserInfoFactory.
            getUserFullName(tmpMtmCalendarRecordMeeting.getCreatorID()));
        tmpMtmCalendarRecordMeeting.setUpdaterName(UserInfoFactory.
            getUserFullName(tmpMtmCalendarRecordMeeting.getUpdaterID()));
        return (tmpMtmCalendarRecordMeeting);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
      } finally {
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }

  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws
      ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = (
        MtmCalendarRecordMeeting) ( (MtmCalendarRecordMeeting) obj).clone();

    synchronized (dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE MTM_CALENDAR_RECORD_MEETING ");
        sqlStat.append("SET    CALENDAR_RECORD_ID=?, INVITED_ID=?, INVITED_ID_TYPE=?, UPDATER_ID=?, UPDATE_DATE=? ");
        sqlStat.append("WHERE  ID=? AND UPDATE_DATE=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        setPrepareStatement(preStat, 1,
                            tmpMtmCalendarRecordMeeting.getCalendarRecordID());
        setPrepareStatement(preStat, 2,
                            tmpMtmCalendarRecordMeeting.getInvitedID());
        setPrepareStatement(preStat, 3,
                            tmpMtmCalendarRecordMeeting.getInvitedIDType());
        setPrepareStatement(preStat, 4, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 5, currTime);
        setPrepareStatement(preStat, 6, tmpMtmCalendarRecordMeeting.getID());
        setPrepareStatement(preStat, 7,
                            tmpMtmCalendarRecordMeeting.getUpdateDate());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        } else {
          tmpMtmCalendarRecordMeeting.setUpdaterID(sessionContainer.
              getUserRecordID());
          tmpMtmCalendarRecordMeeting.setUpdateDate(currTime);
          tmpMtmCalendarRecordMeeting.setCreatorName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getCreatorID()));
          tmpMtmCalendarRecordMeeting.setUpdaterName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getUpdaterID()));
          return (tmpMtmCalendarRecordMeeting);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
      } finally {
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }

  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws
      ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = (
        MtmCalendarRecordMeeting) ( (MtmCalendarRecordMeeting) obj).clone();

    synchronized (dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   MTM_CALENDAR_RECORD_MEETING ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        setPrepareStatement(preStat, 1, tmpMtmCalendarRecordMeeting.getID());
        setPrepareStatement(preStat, 2,
                            tmpMtmCalendarRecordMeeting.getUpdateDate());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        } else {
          return (tmpMtmCalendarRecordMeeting);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
      } finally {
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }

  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws
      ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = (
        MtmCalendarRecordMeeting)this.oldValue;

    if (tmpMtmCalendarRecordMeeting != null) {
      oldValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getID()));
      oldValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.
                                      getCalendarRecordID()));
      oldValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getInvitedID()));
      oldValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.
                                      getInvitedIDType()));
      oldValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getUpdateDate()));
    }

    tmpMtmCalendarRecordMeeting = (MtmCalendarRecordMeeting) obj;
    if (tmpMtmCalendarRecordMeeting != null) {
      newValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getID()));
      newValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.
                                      getCalendarRecordID()));
      newValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getInvitedID()));
      newValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.
                                      getInvitedIDType()));
      newValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpMtmCalendarRecordMeeting.getUpdateDate()));
    }

    auditTrailBase(opMode, oldValues, newValues);
  }

  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *     public Object getObjectBy<Criteria>()                           *
   *     - e.g. public Object getObjectByCode()                          *
   *     public List getListBy<Criteria>()                               *
   *     - e.g. public List getListByUserID()                            *
   * For OPERATION methods, the function name should be in the notation: *
   *     public void <Operation>ObjectBy<Criteria>()                     *
   *     - e.g. public void deleteObjectByCode()                         *
   *     public void <Operation>ListBy<Criteria>()                       *
   *     - e.g. public void deleteListByUserID()                         *
   ***********************************************************************/

  public synchronized void deleteObjectByCalendarID(Integer ID) throws
      ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized (dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   MTM_CALENDAR_RECORD_MEETING ");
        sqlStat.append("WHERE  CALENDAR_RECORD_ID=? AND UPDATE_COUNT=?");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        setPrepareStatement(preStat, 1, ID);
        updateCnt = preStat.executeUpdate();
      }
      /*catch (ApplicationException appEx) {
        throw appEx;
                   } */ catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
      } finally {
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }

  public synchronized List getListByCalendarID(Integer id) throws
      ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List list = new ArrayList();

    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT ID, CALENDAR_RECORD_ID, INVITED_ID, INVITED_ID_TYPE, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE ");
        sqlStat.append("FROM   MTM_CALENDAR_RECORD_MEETING ");
        sqlStat.append("WHERE  CALENDAR_RECORD_ID = ? ");
        sqlStat.append("ORDER BY INVITED_ID ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        this.setPrepareStatement(preStat, 1, id);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = new
              MtmCalendarRecordMeeting();
          tmpMtmCalendarRecordMeeting.setID(getResultSetInteger(rs, "ID"));
          tmpMtmCalendarRecordMeeting.setCalendarRecordID(getResultSetInteger(
              rs, "CALENDAR_RECORD_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedID(getResultSetInteger(rs,
              "INVITED_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedIDType(getResultSetString(rs,
              "INVITED_ID_TYPE"));
          tmpMtmCalendarRecordMeeting.setCreatorID(getResultSetInteger(rs,
              "CREATOR_ID"));
          tmpMtmCalendarRecordMeeting.setCreateDate(getResultSetTimestamp(rs,
              "CREATE_DATE"));
          tmpMtmCalendarRecordMeeting.setUpdaterID(getResultSetInteger(rs,
              "UPDATER_ID"));
          tmpMtmCalendarRecordMeeting.setUpdateDate(getResultSetTimestamp(rs,
              "UPDATE_DATE"));
          tmpMtmCalendarRecordMeeting.setCreatorName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getCreatorID()));
          tmpMtmCalendarRecordMeeting.setUpdaterName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getUpdaterID()));

          list.add(tmpMtmCalendarRecordMeeting);
        }

        return list;
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
      } finally {
        try {
          rs.close();
        } catch (Exception ignore) {} finally {
          rs = null;
        }
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }

  public synchronized List getListByUserID(Integer id) throws
      ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List list = new ArrayList();

    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT ID, CALENDAR_RECORD_ID, INVITED_ID, INVITED_ID_TYPE, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE ");
        sqlStat.append("FROM   MTM_CALENDAR_RECORD_MEETING ");
        sqlStat.append("WHERE  INVITED_ID = ? ");
        sqlStat.append("ORDER BY CALENDAR_RECORD_ID ");
        preStat = dbConn.prepareStatement(sqlStat.toString());
        this.setPrepareStatement(preStat, 1, id);
        rs = preStat.executeQuery();
        while (rs.next()) {
          MtmCalendarRecordMeeting tmpMtmCalendarRecordMeeting = new
              MtmCalendarRecordMeeting();
          tmpMtmCalendarRecordMeeting.setID(getResultSetInteger(rs, "ID"));
          tmpMtmCalendarRecordMeeting.setCalendarRecordID(getResultSetInteger(
              rs, "CALENDAR_RECORD_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedID(getResultSetInteger(rs,
              "INVITED_ID"));
          tmpMtmCalendarRecordMeeting.setInvitedIDType(getResultSetString(rs,
              "INVITED_ID_TYPE"));
          tmpMtmCalendarRecordMeeting.setCreatorID(getResultSetInteger(rs,
              "CREATOR_ID"));
          tmpMtmCalendarRecordMeeting.setCreateDate(getResultSetTimestamp(rs,
              "CREATE_DATE"));
          tmpMtmCalendarRecordMeeting.setUpdaterID(getResultSetInteger(rs,
              "UPDATER_ID"));
          tmpMtmCalendarRecordMeeting.setUpdateDate(getResultSetTimestamp(rs,
              "UPDATE_DATE"));
          tmpMtmCalendarRecordMeeting.setCreatorName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getCreatorID()));
          tmpMtmCalendarRecordMeeting.setUpdaterName(UserInfoFactory.
              getUserFullName(tmpMtmCalendarRecordMeeting.getUpdaterID()));

          list.add(tmpMtmCalendarRecordMeeting);
        }

        return list;
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle);
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.COMMON_FATAL_ERROR, e);
      } finally {
        try {
          rs.close();
        } catch (Exception ignore) {} finally {
          rs = null;
        }
        try {
          preStat.close();
        } catch (Exception ignore) {} finally {
          preStat = null;
        }
      }
    }
  }

}
